package com.vallis.lottery.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vallis.common.annotation.Log;
import com.vallis.common.core.controller.BaseController;
import com.vallis.common.core.domain.AjaxResult;
import com.vallis.common.enums.BusinessType;
import com.vallis.lottery.domain.ContainCalcResult;
import com.vallis.lottery.service.IContainCalcResultService;
import com.vallis.common.utils.poi.ExcelUtil;
import com.vallis.common.core.page.TableDataInfo;

/**
 * 当期结果Controller
 *
 * @author vallis
 * @date 2022-08-10
 */
@RestController
@RequestMapping("/containResult/containResult")
public class ContainCalcResultController extends BaseController
{
    @Autowired
    private IContainCalcResultService containCalcResultService;

    /**
     * 查询当期结果列表
     */
    @PreAuthorize("@ss.hasPermi('containResult:containResult:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContainCalcResult containCalcResult)
    {
        startPage();
        List<ContainCalcResult> list = containCalcResultService.selectContainCalcResultList(containCalcResult);
        return getDataTable(list);
    }

    /**
     * 导出当期结果列表
     */
    @PreAuthorize("@ss.hasPermi('containResult:containResult:export')")
    @Log(title = "当期结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContainCalcResult containCalcResult)
    {
        List<ContainCalcResult> list = containCalcResultService.selectContainCalcResultList(containCalcResult);
        ExcelUtil<ContainCalcResult> util = new ExcelUtil<ContainCalcResult>(ContainCalcResult.class);
        util.exportExcel(response, list, "当期结果数据");
    }

    /**
     * 获取当期结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('containResult:containResult:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(containCalcResultService.getById(id));
    }

    /**
     * 新增当期结果
     */
    @PreAuthorize("@ss.hasPermi('containResult:containResult:add')")
    @Log(title = "当期结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContainCalcResult containCalcResult) {
        return toAjax(containCalcResultService.save(containCalcResult));
    }

    /**
     * 修改当期结果
     */
    @PreAuthorize("@ss.hasPermi('containResult:containResult:edit')")
    @Log(title = "当期结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContainCalcResult containCalcResult) {
        return toAjax(containCalcResultService.updateById(containCalcResult));
    }

    /**
     * 删除当期结果
     */
    @PreAuthorize("@ss.hasPermi('containResult:containResult:remove')")
    @Log(title = "当期结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(containCalcResultService.removeByIds(Arrays.asList(ids)));
    }
}
